﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Web.API.IDAL;

namespace Web.API.DAL
{
    public class MemberDAL<T>:MemberIDAl<T> where T : class
    {
        public MemberDAL(MyContext context) 
        {
            Context = context;
        }
        public MyContext Context { get; }

        public Task<int> AddAsync(T t)
        {
            Context.Set<T>().AddAsync(t);
            return Context.SaveChangesAsync();
        }

        public Task<int> AddRangeAsync(List<T> list)
        {
           Context.Set<T>().AddRangeAsync(list);
            return Context.SaveChangesAsync();
        }

        public Task<int> DeleteAsync(T t)
        {
            Context.Set<T>().Remove(t);
            return Context.SaveChangesAsync();
        }

        public Task<int> DeleteRangeAsync(List<T> list)
        {
           Context.Set<T>().RemoveRange(list);
            return Context.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return Context.Set<T>();
        }

        public Task<int> UpdateAsync(T t)
        {
            Context.Set<T>().Update(t);
            return Context.SaveChangesAsync();
        }

        public Task<int> UpdateRangeAsync(List<T> list)
        {
           Context.Set<T>().UpdateRange(list);
            return Context.SaveChangesAsync();
        }
    }
}
